/*
 * TCSS 360 - Winter 2014
 * TESK Software
 */
package view.personalInfo;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import view.MainFrame;
import view.userProfile.AuthorView;
import java.awt.Color;
import java.awt.Font;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.BevelBorder;

/**
 * Allows a Author to input their personal information into their profile.
 * 
 * @author Kon
 * @version 3/3/14.
 */
@SuppressWarnings("serial")
public class ContactView extends JPanel {

	/** The text field the user enters their first name into. */
	private JTextField my_firstname;
	
	/** The text field the user enters their last name into. */
	private JTextField my_lastname;
	
	/** The text field the user enters their home address into. */
	private JTextField my_homeadd;
	
	/** The text field the user enters their phone number into. */
	private JTextField my_homephone;
	
	/** The frame this panel is associated with. */
	private MainFrame my_frame;
	
	/**
	 * Constructs the contact view panel.
	 * 
	 * @param the_frame the frame to associate the panel with
	 */
	public ContactView(MainFrame the_frame){		//super("Contact Information");
		super();
		my_frame  = the_frame;
		init();
	}
	
	/**
	 * Adds the panels of the current panel.
	 */
	private void init(){
		this.setLayout(new GridLayout(5,0));
		this.add(titlePanel());
		this.add(contactPanel());
		this.add(profLabelPanel());
		this.add(profPanel());
		this.add(buttonPanel());
	}
	
	/**
	 * A panel containing all labels and textbox in Contact Information.
	 * @return panel the panel to attach
	 */
	private JPanel contactPanel(){
		final JPanel panel = new JPanel(new GridLayout(4,4));
		panel.setBackground(new Color(255, 245, 238));
		//panel.setPreferredSize(new Dimension(200,100));
		
		final JLabel firstname = new JLabel("First name: ");
		final JLabel lastname = new JLabel("Last name: ");
		final JLabel homeadd = new JLabel("Home Address: ");
		final JLabel homephone = new JLabel("Home Phone: ");
		
		my_firstname = new JTextField(20);
		my_lastname = new JTextField(20);
		my_homeadd = new JTextField(20);
		my_homephone = new JTextField(20);

		
		//adding all labels textfields and actionlistener here.
		panel.add(firstname);
		panel.add(my_firstname);
		panel.add(lastname);
		panel.add(my_lastname);
		panel.add(homeadd);
		panel.add(my_homeadd);
		panel.add(homephone);
		panel.add(my_homephone);
	
		JPanel base = new JPanel();
		base.setBackground(new Color(255, 245, 238));
		base.add(panel);
		return base;
	}
	
	/**
	 * Provides a button panel for the current panel.
	 * 
	 * @return the button panel
	 */
	private JPanel buttonPanel() {
		final JPanel buttonPanel = new JPanel();
		buttonPanel.setBorder(new SoftBevelBorder(BevelBorder.RAISED, null, null, null, null));
		buttonPanel.setBackground(new Color(224, 255, 255));
		final JButton next = new JButton("Finish");
		next.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// save user profile
				// identify user role
				my_frame.setNewPanel(new AuthorView(my_frame));
				// pull up GUI accordingly
			}
		});
		final JButton skip = new JButton("Cancel");
		skip.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// identify user role
				// pull up GUI accordingly
				JPanel panel = new AuthorView(my_frame);
				my_frame.setNewPanel(panel);
			}
		});
		
		buttonPanel.add(skip);
		buttonPanel.add(next);
		return buttonPanel;
	}
	
	/**
	 * Provides a panel where the title is displayed
	 * @return panel the panel with the title displayed
	 */
	private JPanel titlePanel(){
		final JPanel panel = new JPanel(new GridLayout(2,0));
		panel.setBackground(new Color(224, 255, 255));
		panel.setPreferredSize(new Dimension(200,40));
		final JLabel label = new JLabel("Personal Information");
		label.setForeground(new Color(148, 0, 211));
		label.setFont(new Font("Tahoma", Font.PLAIN, 14));
		final JLabel label1 = new JLabel("Contact");
		label1.setForeground(new Color(148, 0, 211));
		label1.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		panel.add(label);
		panel.add(label1);
		return panel;
	}
	
	/**
	 * Provides a small panel to separate look.
	 * @return panel the created panel 
	 */
	private JPanel profLabelPanel(){
		final JPanel panel = new JPanel (new GridLayout(0,1));
		panel.setBackground(new Color(255, 245, 238));
		final JLabel label = new JLabel("Professional");
		label.setForeground(new Color(148, 0, 211));
		label.setFont(new Font("Tahoma", Font.PLAIN, 14));
		label.setBackground(new Color(148, 0, 211));
		panel.add(label);
		return panel;
	}
	
	/**
	 * Provides a panel with the professional information.
	 * 
	 * @return panel with labels and text.
	 */
	private JPanel profPanel(){
		final JPanel panel = new JPanel(new GridLayout(4,4));
		panel.setBackground(new Color(255, 245, 238));
		
		final JLabel occu_label = new JLabel("Occupation: ");
		final JLabel inst_label = new JLabel("Institution: ");
		final JLabel job_label = new JLabel("Job Title: ");
		final JLabel others_label = new JLabel("Others: ");
		
		JTextField occu = new JTextField(20);
		JTextField inst = new JTextField(20);
		JTextField job = new JTextField(20);
		JTextField others = new JTextField(20);
		
		panel.add(occu_label);
		panel.add(occu);
		panel.add(inst_label);
		panel.add(inst);
		panel.add(job_label);
		panel.add(job);
		panel.add(others_label);
		panel.add(others);
		
		final JPanel base = new JPanel();
		base.setBackground(new Color(255, 240, 245));
		base.add(panel);
		return base;
	}
}
